<extend name="Public/base" />

<block name="body">
	<!-- 标题栏 -->
	<div class="main-title">
		<h2>友情链接管理</h2>
	</div>
	<div class="cf">
		<div class="fl">
        <a class="btn" href="{:U('increase')}">新 增</a>
        <button class="btn ajax-post" url="{:U('setStatus',array('status'=>1))}" target-form="ids">启 用</button>
        <button class="btn ajax-post" url="{:U('setStatus',array('status'=>0))}" target-form="ids">禁 用</button>
        <button class="btn ajax-post confirm" url="{:U('setStatus',array('status'=>-1))}" target-form="ids">删 除</button>
    </div>

    <!-- 高级搜索 -->
		<div class="search-form fr cf">
			<div class="sleft">
				<input type="text" name="linkname" class="search-input" value="{:I('linkname')}" placeholder="请输入链接名称/公司名称/ID">
				<a class="sch-btn" href="javascript:;" id="search" url="{:U('friendlink/link')}"><i class="btn-search"></i></a>
			</div>
		</div>
    </div>
    <!-- 数据列表 -->
    <div class="data-table table-striped">
	<table id = 'tab' class="">
    <thead>
        <tr>
        		<th class="row-selected row-selected"><input class="check-all" type="checkbox"/></th>
        		<th class="">ID</th>
        		<th class="">公司名称</th>
        		<th class="">链接名称</th>
        		<th class="">链接</th>
        		<th class="">状态</th>
        		<th class="">添加时间</th>
        		<th class="">操作</th>
    		</tr>
    </thead>
    <tbody>

		<notempty name="data">
		<!-- 遍历开始 -->
		<foreach name="data" item="val">
		<tr id="trr">
			<td>
				<input class="ids" type="checkbox" name="ids[]" value="{$val.id}" />
			</td>
			<td>{$val.id}</td>
			<td>{$val.company}</td>
			<td>{$val.linkname}</td>
			<td>{$val.link}</td>
			<td sta="sta">{$val.status}</td>
			<td>{$val.addtime|date="Y-m-d",###}</td>
			<td>
				<eq name="vo.status" value="1">
					<a href="{:U('User/changeStatus?method=forbidUser&id='.$vo['uid'])}" class="ajax-get">禁用</a>
				<else/>
				</eq>
				<a class='modify' href='{:U("modify",array("id"=>$val["id"]))}' >编辑</a>
                <!-- <a class='use' href="#" >禁用</a> -->
                <!-- <a class='' href="#" >删除</a> -->
                
            </td>
		</tr>
		</foreach>
		<!-- 遍历结束 -->

		<else/>
		<td colspan="9" class="text-center"> aOh! 暂时还没有内容! </td>
		</notempty>
	</tbody>
    </table>
	</div>
    <div class="page">
        {$_page}
    </div>
</block>

<block name="script">
	<script src="__STATIC__/thinkbox/jquery.thinkbox.js"></script>

	<script type="text/javascript">
	//搜索功能
	$("#search").click(function(){
		var url = $(this).attr('url');
        var query  = $('.search-form').find('input').serialize();
        query = query.replace(/(&|^)(\w*?\d*?\-*?_*?)*?=?((?=&)|(?=$))/g,'');
        query = query.replace(/^&/g,'');
        if( url.indexOf('?')>0 ){
            url += '&' + query;
        }else{
            url += '?' + query;
        }
		window.location.href = url;
	});
	//回车搜索
	$(".search-input").keyup(function(e){
		if(e.keyCode === 13){
			$("#search").click();
			return false;
		}
	});
    //导航高亮
    highlight_subnav('{:U('User/index')}');
	</script>

	<script>

		// 设置右边的状态按钮
		$('#trr td[sta=sta]').each(function(i){
			var str = $(this).html();
			if (str == '禁用') {
				$(this).next().next().children().eq(1).html('启用');
			}else{
				$(this).next().next().children().eq(1).html('禁用');
			}

		});

		$('.use').click(function()
		{

			// 获取当前状态
			var staname = $(this).parent().prev().prev().html();

			// ajax修改状态
			var id = $(this).parent().parent().children().eq(1).html();
			var status = $(this).parent().parent().children().eq(5).html();

			$.get("{:U('status')}" , {id : id , status : status} , function(data)
			{
				console.dir(data);

			});

			//动态改变状态
			if (staname == '禁用') {
				$(this).html('禁用');
				$(this).parent().prev().prev().html('启用');
			}else{
				$(this).html('启用');
				$(this).parent().prev().prev().html('禁用');
			}

		});
		


	</script>



</block>
